#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "czhpacktool.h"



int main(int argc, char *argv[])
{
    unsigned char *src,*dst;
    int operation = 0;//0:encode(default),1:decode
    int i;

    src = dst = NULL;
    if(argc < 5)
    {
        printf("czhpack打包和解包工具\n");
        printf("用法：\n");
        printf("打包 %s -e -o 输出文件 输入目录\n", argv[0]);
        printf("解包 %s -d -o 输出目录 输入文件\n", argv[0]);
        printf("注意：\n");
        printf("包内文件名不要超过7个字母和数字。\n");
        return 0;
    }
    i = 1;
    while(i<argc)
    {
        if(strcmp(argv[i],"-o")==0)
        {
            i++;
            if(i<argc)
            {
                dst = argv[i];
            }
        }
        else if(strcmp(argv[i],"-e")==0)
        {
            operation = 0;
        }
        else if(strcmp(argv[i],"-d")==0)
        {
            operation = 1;
        }
        else
        {
            src = argv[i];
        }
        i++;
    }

    if(src && dst)
    {
        if(operation == 0)
        {
            if(czhpack_pack(dst,src))
            {
                printf("打包成功！\n");
            }
            else
            {
                printf("打包出错！\n");
            }
        }
        else
        {
            if(czhpack_unpack(src,dst))
            {
                printf("解包成功！\n");
            }
            else
            {
                printf("解包出错！\n");
            }
        }
    }
    return 0;
}
